# coding: utf-8
from PySide6.QtCore import QSize
from qfluentwidgets import TransparentToolButton
from qframelesswindow.titlebar.title_bar_buttons import TitleBarButtonState

from common import Icon


class TitleBarButton(TransparentToolButton):
    def _postInit(self):
        self.setFixedSize(36, 36)
        self.setIconSize(QSize(18, 18))
        self._state = TitleBarButtonState.NORMAL

    def state(self):
        return self._state

    def setState(self, state):
        """ set the state of button

        Parameters
        ----------
        state: TitleBarButtonState
            the state of button
        """
        self._state = state
        self.update()


class MaximizeButton(TitleBarButton):
    """ Maximize button """

    def _postInit(self):
        super()._postInit()
        self._isMax = False

    def setMaxState(self, isMax):
        """ update the maximized state and icon """
        if isMax:
            self.setIcon(Icon.MAX)
        else:
            self.setIcon(Icon.NORMAL)
        if self._isMax == isMax:
            return

        self._isMax = isMax
        self.setState(TitleBarButtonState.NORMAL)